﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace PeisongWeb.admin
{
    public partial class homeList : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("AH", 1))
                {
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        private void rptBind()
        {
            DataTable dt = logic.home.list();
            if (dt != null && dt.Rows.Count > 0)
            {
                DataView v1 = new DataView(dt);
                v1.RowFilter = "Area=1";
                if (v1.Count > 0)
                {
                    //Library.Resource.UploadPath + Library.Resource.FileOriginal + "/" + v1[0]["FileName"].ToString();
                    rpt_imgList.DataSource = v1;
                    rpt_imgList.DataBind();
                }

                DataView v2 = new DataView(dt);
                v2.RowFilter = "Area=2";
                if (v2.Count > 0)
                {
                    rpt_sysInfoList.DataSource = v2;
                    rpt_sysInfoList.DataBind();
                }
                DataView v3 = new DataView(dt);
                v3.RowFilter = "Area=3";
                if (v3.Count > 0)
                {
                    rpt_list.DataSource = v3;
                    rpt_list.DataBind();
                }
            }
        }
        protected void rpt_list_ItemCommand(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int homeId = 0;
                if (e.CommandArgument != null)
                {
                    int.TryParse(e.CommandArgument.ToString(), out homeId);

                    DAL.HomeEntity home = logic.home.getById(homeId);
                    if (home.FileName != "")
                    {
                        Library.FileLib.Del(Library.Resource.UploadPath + Library.Resource.FileOriginal + "/" + home.FileName);
                    }
                    logic.home.delete(homeId);
                    Library.Script.ClientMsg("删除成功！");
                }
                rptBind();
            }
        }
    }
}
